package com.mrx.pvzcommunity.dao;

import com.mrx.pvzcommunity.model.thread.Comment;
import com.mrx.pvzcommunity.model.user.User;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface CommentDao {

    @Select("SELECT * FROM comments WHERE uid = #{uid}")
    @Result(property = "user", column = "uid", javaType = User.class,
            one = @One(select = "com.mrx.pvzcommunity.dao.UserDao.findUserByUid")
    )
    List<Comment> findCommentByUid(@Param("uid") String uid);

    @Select("SELECT * FROM comments WHERE tid = #{tid}")
    @Result(property = "user", column = "uid", javaType = User.class,
            one = @One(select = "com.mrx.pvzcommunity.dao.UserDao.findUserByUid")
    )
    List<Comment> findCommentByTid(@Param("tid") String tid);

    @Insert("INSERT INTO comments(tid,uid,content) VALUES(#{tid},#{uid},#{content})")
    Boolean addCommentByTid(@Param("tid") String tid, @Param("uid") String uid, @Param("content") String content);
}
